package 枚举与尺聚法;

import java.util.Arrays;
import java.util.LinkedList;

//全排列 无重复

public class 全排列2 {
    public static void main(String[] args) {
        int[] ints = {1, 1, 3};
        boolean[] Flag = new boolean[ints.length];
        Arrays.sort(ints);
        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        dfs(ints, Flag, linkedList);
    }

    private static void dfs(int[] ints, boolean[] flag, LinkedList linkedList) {
        if (linkedList.size() == ints.length) {
            System.out.println(linkedList);
            return;
        }

        for (int i = 0; i < ints.length; i++) {
            if (i > 0 && ints[i] == ints[i - 1] && !flag[i - 1]) {
                continue;
            }
            if (!flag[i]) {
                linkedList.addLast(ints[i]);
                flag[i] = true;
                dfs(ints, flag, linkedList);
                flag[i] = false;
                linkedList.removeFirst();
            }
        }
    }

}
